package com.irdstudio.efp.nls.service.yed.common.rules.apply;

import com.irdstudio.basic.framework.core.constant.EsbRetCodeStandard;
import com.irdstudio.basic.framework.core.exception.BizException;
import com.irdstudio.basic.framework.core.util.DateUtility;
import com.irdstudio.efp.nls.service.yed.common.rules.CheckRule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 需求编号:2019D08--
 * 问题编号:
 * 开发人员: caoxin
 * 创建日期:2020/3/30
 * 功能描述:
 * 修改日期:2020/3/30
 * 修改描述:
 */
public class TheLastLoanDateAndLmtExpireDateRule implements CheckRule {
    private Logger logger = LoggerFactory.getLogger(TheLastLoanDateAndLmtExpireDateRule.class);

    private final String signDate;
    private final String useCrdtAppSrlNo;
    private final String openday;
    private final String loanTerm;

    public TheLastLoanDateAndLmtExpireDateRule(String signDate, String useCrdtAppSrlNo, String openday,String loanTerm) {
        this.signDate = signDate;
        this.useCrdtAppSrlNo = useCrdtAppSrlNo;
        this.openday = openday;
        this.loanTerm = loanTerm;
    }

    @Override
    public void check() throws BizException {
        // 规则为贷款期限 openday+贷款期限 > signDate + 一年 拒绝
        if (DateUtility.ADD_MONTH(openday, Integer.parseInt(loanTerm)).compareTo(DateUtility.ADD_MONTH(signDate, 12)) > 0) {
            logger.error("用信申请流水号【" + useCrdtAppSrlNo + "】，贷款期限不在额度有效期内！");
            throw new BizException(EsbRetCodeStandard.WFJKYWGZ.getValue(), "用信申请流水号【" + useCrdtAppSrlNo + "】，贷款期限不在额度有效期内！");
        }
    }
}
